/**
 * Created by zhaojm on 15/4/23.
 */
game.Ball = game.BaseRole.extend({
    _sprite : null,
    _layer : null,


    _speedY : null,
    _speedX : null,
    _gravity : null,

    _DEFAULT_GRAVITY : -2000,
    _DEFAULT_SPEED_X : 500,
    _DEFAULT_SPEED_BOUNCE_Y : -2000,
    _DEFAULT_SPEED_JUMP_Y : 1000,

    _className : "Ball",
    ctor:function(p){
        this._super();

        var sprite = new cc.Sprite(res.ball_png);
        sprite.x = p.x;
        sprite.y = p.y;
        this._sprite = sprite;
        this._gravity = this._DEFAULT_GRAVITY;
        this._speedY = this._DEFAULT_SPEED_BOUNCE_Y;

    },

    update:function(dt){
        this._sprite.x += this._speedX * dt;
        if(this._sprite.x < game._Camera.x){
            this._sprite.x = game._Camera.x;
        }

        this._speedY += this._gravity * dt;

        this._sprite.y += 0.5 * this._gravity * dt * dt + this._speedY * dt;
        cc.log(this._speedY);
    },

    addToLayer : function(layer, world){
        this._layer = layer;
        layer.addChild(this._sprite);
    },

    removeFromLayer:function(){
        this._sprite.removeFromParent();

    },

    getCollideRect:function(){
        var pos = this._sprite.getPosition();
        var contentSize = this._sprite.getContentSize();
        return new cc.Rect(pos.x - contentSize.width / 2, pos.y - contentSize.height / 2, contentSize.width, contentSize.height);
    },

    bounce : function(){
        //cc.log('bounce..');
        this._speedY = this._DEFAULT_SPEED_BOUNCE_Y;
    },

    startRun:function(){
        this._speedX = this._DEFAULT_SPEED_X;
    },

    jump:function(){
        this._speedY = this._DEFAULT_SPEED_JUMP_Y;
    },


});